<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import = "com.xff.bean.HistoryBean" %>
<%@ page import = "com.xff.dao.AdminDao" %>
<%@ page import = "com.xff.dao.TypeDao" %>
<%@ page import = "com.xff.dao.BookDao" %>
<%@ page import = "com.xff.bean.AdminBean" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="zh-CN" class="ax-vertical-centered">
<head>
	<meta charset="UTF-8">
	<title>图书馆管理系统</title>
	    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="css/bootstrap.min.css">
	    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/bootstrap-admin-theme.css">
        <link rel="stylesheet" href="css/bootstrap-admin-theme.css">
        <script src="js/bootstrap.min.js"></script>
        <script src="jQuery/jquery-3.1.1.min.js"></script>
            <script src="js/bootstrap-dropdown.min.js"></script>
                      
              <script src="ajax-lib/ajaxutils.js"></script>
            <script src="js/adminUpdateInfo.js"></script>
             <script src="js/adminUpdatePwd.js"></script>
       
</head>



<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>


<body class="bootstrap-admin-with-small-navbar">
<%
AdminBean admin = new AdminBean();
String aid = (String)session.getAttribute("aid");
AdminDao admindao = new AdminDao();
admin = admindao.get_AidInfo2(aid);

%>
    <nav class="navbar navbar-inverse navbar-fixed-top bootstrap-admin-navbar bootstrap-admin-navbar-under-small" role="navigation">
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <div class="collapse navbar-collapse main-navbar-collapse">
                        <a class="navbar-brand" href="/admin"><strong>欢迎使用图书馆管理系统</strong></a>
                        <ul class="nav navbar-nav navbar-right">
                            <li class="dropdown">
                                <a href="#" role="button" class="dropdown-toggle" data-hover="dropdown"> <i class="glyphicon glyphicon-user"></i> 欢迎您，管理员 <%=admin.getName()%> <i class="caret"></i></a>
                            
                                 <ul class="dropdown-menu">
                                     <li><a href="#updateinfo" data-toggle="modal">个人资料</a></li>
                                      <li role="presentation" class="divider"></li>
                                       <li><a href="#updatepwd" data-toggle="modal">修改密码</a></li>
                                        <li role="presentation" class="divider"></li>
                                    <li><a href="/login">退出</a></li>
                                </ul>
                                
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </nav>

    <div class="container">
        <!-- left, vertical navbar & content -->
        <div class="row">
            <!-- left, vertical navbar -->
            <div class="col-md-2 bootstrap-admin-col-left">
                <ul class="nav navbar-collapse collapse bootstrap-admin-navbar-side">
					<li>
						<a href="/admin_book"><i class="glyphicon glyphicon-chevron-right"></i> 图书管理</a>
					</li>
					<li>
						<a href="/admin_user"><i class="glyphicon glyphicon-chevron-right"></i> 读者管理</a>
					</li>
					<li>
						<a href="/admin_booktype"><i class="glyphicon glyphicon-chevron-right"></i> 图书分类管理</a>
					</li>
					<li>
						<a href="/admin_apply"><i class="glyphicon glyphicon-chevron-right"></i> 图书借阅申请</a>
					</li>
					<li>
						<a href="/admin_borrow"><i class="glyphicon glyphicon-chevron-right"></i> 图书借阅信息</a>
					</li>
					<li>
						<a href="/admin_history"><i class="glyphicon glyphicon-chevron-right"></i> 图书归还信息</a>
					</li>
					<li>
						<a href="/admin_loss"><i class="glyphicon glyphicon-chevron-right"></i> 图书挂失信息</a>
					</li>
					<li>
						<a href="/admin_subscribe"><i class="glyphicon glyphicon-chevron-right"></i> 图书预约信息</a>
					</li>
					<li>
						<a href="/admin_penalty"><i class="glyphicon glyphicon-chevron-right"></i> 罚款缴费</a>
					</li>
					<li>
						<a href="/admin_seat"><i class="glyphicon glyphicon-chevron-right"></i> 座位管理</a>
					</li>
                </ul>
                
            </div>

            <!-- content -->
            <div class="col-md-10">
                
                
              <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-default bootstrap-admin-no-table-panel">
                            <div class="panel-heading">
                                <div class="text-muted bootstrap-admin-box-title">图书借阅信息查询</div>
                            </div>

							<div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
								<form class="form-horizontal" action="/SelectBorrowServlet" method="post">
									<input type="hidden" name="tip" value="1">
									<div class="col-lg-7 form-group">
										<label class="col-lg-4 control-label" for="bookName">图书名称</label>
										<div class="col-lg-8">
											<input class="form-control" id="bookName" name="name" type="text" value="">
											<label class="control-label" for="bookName" style="display: none;"></label>
										</div>
									</div>
									<div class="col-lg-3 form-group">

										<button type="submit" class="btn btn-primary" id="btn_query" onclick="">查询</button>
									</div>

								</form>
							</div>

							<div class="bootstrap-admin-no-table-panel-content bootstrap-admin-panel-content collapse in">
								<form class="form-horizontal" action="/SelectBorrowServlet" method="post">
									<input type="hidden" name="tip" value="2">
									<div class="col-lg-7 form-group">
										<label class="col-lg-4 control-label" for="bookName2">读者账户/姓名</label>
										<div class="col-lg-8">
											<input class="form-control" id="bookName2" name="name" type="text" value="">
											<label class="control-label" for="bookName2" style="display: none;"></label>
										</div>
									</div>
									<div class="col-lg-3 form-group">

										<button type="submit" class="btn btn-primary" id="btn_query2" onclick="">查询</button>
									</div>

								</form>
							</div>
                           
                        </div>
                    </div>
                </div>
                
                
                <div class="row">
                    <div class="col-lg-12">
                        <table id="data_list" class="table table-hover table-bordered" cellspacing="0" width="100%">
                            <thead>
                            <tr>
                                <th>图书号</th>
                                <th>图书名称</th>
                                <th>读者账号</th>
                                <th>读者名称</th>
                                <th>借阅日期</th>
                                <th>截止还书日期</th>
								<th>借阅状态</th>
                                <th>操作</th>
                                
                            </tr>
                            </thead>
                            
                            
                            <!---在此插入信息-->
                             <%
                             ArrayList<HistoryBean> bookdata = new ArrayList<HistoryBean>();
                             bookdata = (ArrayList<HistoryBean>)request.getAttribute("data");
                           if(bookdata==null){
                        	   BookDao bookdao = new BookDao();
                        	   bookdata = (ArrayList<HistoryBean>)bookdao.get_HistoryListInfo3(1,4);
                           }
  for (HistoryBean bean : bookdata){
  %>                 
                            	<tbody>
	                         	   	<td><%= bean.getCard() %></td>
	                         	   	<td><%= bean.getBookname() %></td>
	                                <td><%= bean.getAdminname() %></td>
	                                <td><%= bean.getUsername() %></td>
	                                <td><%= bean.getBegintime() %></td>
	                                <td><%= bean.getEndtime() %></td>
									<td><%= bean.getStatus()==1?"正常":"超期" %></td>
<td><button type="button" class="btn btn-warning btn-xs" data-toggle="modal" <%--data-target="#updateModal"--%>
id="btn_update" onclick="haibook(<%= bean.getHid()%>,<%=bean.getBid()%>,<%=bean.getAid()%>,'<%=bean.getUsername()%>')">还书</button>

	<button type="button" class="btn btn-danger btn-xs" onclick="losebook(<%= bean.getHid() %>,<%=bean.getBid()%>,<%=bean.getAid()%>)">挂失</button>
	</td>                                            
                          	  </tbody>
                       <%} %> 
                        </table>
                    </div>
                </div>
        </div>
    </div>
    <script type="text/javascript">
    function haibook(hid,bid,aid,username) {

        myAjax("post","/SelectIsPenaltyServlet",{name:username},function (data) {
            if(data=="no"){
                con=confirm("是否还书?");
                if(con==true){
                    location.href = "/BorrowServlet?tip=2&show=2&hid="+hid+"&bid="+bid+"&aid="+aid;
                }
            }else {
                con=confirm("该读者存在罚款未交记录");
                con=confirm("是否还书?");
                if(con==true){
                    location.href = "/BorrowServlet?tip=2&show=2&hid="+hid+"&bid="+bid+"&aid="+aid;
                }
            }

        },"");
    }
    function losebook(hid,bid,aid) {
        con=confirm("是否挂失?");
        if(con==true){
            location.href = "/LoseBookServlet?hid="+hid+"&bid="+bid+"&aid="+aid;
        }
    }


    function myAjax(method,url,data,callback,type){
        //创建兼容 XMLHttpRequest 对象
        var xhr;
        if (window.XMLHttpRequest){//IE7+, Firefox, Chrome, Opera, Safari
            xhr=new XMLHttpRequest();
        }else{// code for IE6, IE5
            xhr=new ActiveXObject("Microsoft.XMLHTTP");
        }

        //给请求添加状态变化事件处理函数
        xhr.onreadystatechange = function (){
            //判断状态码
            if(xhr.status==200 && xhr.readyState==4){
                //根据type参数，判断返回的内容需要进行怎样的处理
                if(type=='json'){
                    //获得 json 形式的响应数据，并使用parse方法解析
                    var res = JSON.parse(xhr.responseText);
                }else if(type=='xml'){
                    //获得 XML 形式的响应数据
                    var res = responseXML;
                }else{
                    //获得字符串形式的响应数据
                    var res = xhr.responseText;
                }
                //调用回调函数,并将响应数据传入回调函数
                callback(res);
            }
        };

        //判断data是否有数据
        var param = '';
        //这里使用stringify方法将js对象格式化为json字符串
        if(JSON.stringify(data) != '{}'){
            url += '?';
            for(var i in data){
                param += i+'='+data[i]+'&';   //将js对象重组，拼接成url参数存入param变量中
            }
            //使用slice函数提取一部分字符串，这里主要是为了去除拼接的最后一个&字符
            //slice函数：返回一个新的字符串。包括字符串从 start 开始（包括 start）到 end 结束（不包括 end）为止的所有字符。
            param = param.slice(0,param.length-1);
        }

        //判断method是否为get
        if(method == "get"){
            //是则将数据拼接在url后面
            url = url+param;
        }


        //初始化请求
        xhr.open(method,url,true);

        //如果method == post
        if(method == "post"){
            xhr.setRequestHeader('content-type','application/x-www-form-urlencoded;charset=utf-8');
            //发送请求
            xhr.send(param);
        }else{
            //发送请求
            xhr.send(null);
        }

    }
    </script>
    
     
                                     <!-- 修改模态框（Modal） -->
                                     <!-------------------------------------------------------------->  
                                
                                        <!-- 修改模态框（Modal） -->
                               <form class="form-horizontal" method="post" action="/UpdateBookServlet">   <!--保证样式水平不混乱-->
									<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="updateModalLabel" aria-hidden="true">
										<div class="modal-dialog">
											<div class="modal-content">
												<div class="modal-header">
													<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
														&times;
													</button>
													<h4 class="modal-title" id="updateModalLabel">
														修改图书分类
													</h4>
												</div>
												<div class="modal-body">
												
										<!---------------------表单-------------------->
										
										 <div class="form-group">
											<label for="updateBookName" class="col-sm-3 control-label">图书名称</label>
												<div class="col-sm-7">
													<input type="text" class="form-control" id="updateBookName" name="name"  placeholder="请输入图书名称">
												<label class="control-label" for="updateBookName" style="display: none;"></label>
												</div>
										</div>
											
										</div>
												<div class="modal-footer">
													<button type="button" class="btn btn-default" data-dismiss="modal">关闭
													</button>
													<button type="submit" class="btn btn-primary" >
														修改
													</button>
												</div>
											</div><!-- /.modal-content -->
										</div><!-- /.modal -->
									</div>
	
                                 </form>
                                   <!-------------------------------------------------------------->
 
    
    
    
    
    
    
     <!--------------------------------------添加的模糊框------------------------>  
                                 <form class="form-horizontal" method="post" action="/AddBookServlet">   <!--保证样式水平不混乱-->
                                        <!-- 模态框（Modal） -->
									<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
										<div class="modal-dialog">
											<div class="modal-content">
												<div class="modal-header">
													<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
														&times;
													</button>
													<h4 class="modal-title" id="addModalLabel">
														添加新图书分类
													</h4>
												</div>
												<div class="modal-body">
												
										<!---------------------表单-------------------->
										
										 <div class="form-group">
											<label for="addBookName" class="col-sm-3 control-label">分类名称</label>
												<div class="col-sm-7">
													<input type="text" class="form-control" id="addBookName" required="required" name="name"  placeholder="请输入图书名称">
													<label class="control-label" for="addBookName" style="display: none;"></label>	
												</div>
										</div>
										
										<!---------------------表单-------------------->
									</div>
												<div class="modal-footer">
													<button type="button" class="btn btn-default" data-dismiss="modal">关闭
													</button>
													<button type="submit" class="btn btn-primary" >
														添加
													</button>
												</div>
											</div><!-- /.modal-content -->
										</div><!-- /.modal -->
									</div>

                                 </form>	
 								<!--------------------------------------添加的模糊框------------------------>



		<!-------------------------修改密码的模糊框------------------------------------->

		<form class="form-horizontal" method="post" action="/AdminServlet">   <!--保证样式水平不混乱-->
			<!-- 模态框（Modal） -->
			<div class="modal fade" id="updatepwd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
								&times;
							</button>
							<h4 class="modal-title" id="updatepasswordModalLabel">
								修改密码
							</h4>
						</div>
						<div class="modal-body">

							<!--正文-->
							<input type="hidden" name="tip" value="1">
							<input type="hidden" name="url" value="admin_borrow">
							<div class="form-group">
								<label for="oldPwd" class="col-sm-3 control-label">原密码</label>
								<div class="col-sm-7">
									<input type="password" class="form-control" name="password" id="oldPwd"  placeholder="请输入原密码">
									<label class="control-label" for="oldPwd" style="display: none"></label>
								</div>
							</div>

							<div class="form-group">
								<label for="newPwd" class="col-sm-3 control-label">新密码</label>
								<div class="col-sm-7">
									<input type="password" class="form-control" name="password2" id="newPwd"  placeholder="请输入新密码">
									<label class="control-label" for="newPwd" style="display: none"></label>
								</div>
							</div>

							<!--正文-->
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭
							</button>
							<button type="submit" class="btn btn-primary" >
								修改
							</button>
						</div>
					</div><!-- /.modal-content -->
				</div><!-- /.modal -->
			</div>

		</form>
		<!-------------------------------------------------------------->


		<!-------------------------个人资料模糊框------------------------------------->

		<form class="form-horizontal" method="post" action="/AdminServlet">   <!--保证样式水平不混乱-->
			<!-- 模态框（Modal） -->
			<div class="modal fade" id="updateinfo" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
								&times;
							</button>
							<h4 class="modal-title" id="ModalLabel">
								个人资料
							</h4>
						</div>

						<div class="modal-body">

							<!--正文-->
							<input type="hidden" name="tip" value="2">
							<input type="hidden" name="url" value="admin_borrow">
							<div class="form-group">
								<label for="name" class="col-sm-3 control-label">真实姓名</label>
								<div class="col-sm-7">
									<input type="text" class="form-control" id="name" name="name" placeholder="请输入您的真实姓名" value='<%=admin.getName()%>'>
									<label class="control-label" for="name" style="display: none"></label>
								</div>
							</div>

							<div class="form-group">
								<label for="phone" class="col-sm-3 control-label">手机号</label>
								<div class="col-sm-7">
									<input type="text" class="form-control" id="phone" name="phone" placeholder="请输入您的手机号" value='<%=admin.getPhone()%>'>
									<label class="control-label" for="phone" style="display: none"></label>
								</div>
							</div>


							<div class="form-group">
								<label for="email" class="col-sm-3 control-label">邮箱</label>
								<div class="col-sm-7">
									<input type="text" class="form-control" id="email" name="email"  placeholder="请输入您的邮箱" value='<%=admin.getEmail()%>'>
									<label class="control-label" for="email" style="display: none"></label>
								</div>
							</div>

							<!--正文-->


						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭
							</button>
							<button type="submit" class="btn btn-primary" >
								修改
							</button>
						</div>
					</div><!-- /.modal-content -->
				</div><!-- /.modal -->
			</div>

		</form>
		<!-------------------------------------------------------------->
    

    <div class="modal fade" id="modal_info" tabindex="-1" role="dialog" aria-labelledby="addModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="infoModalLabel">提示</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-lg-12" id="div_info"></div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" id="btn_info_close" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>



	</div>
</body>
</html>